#include "AICohesion.h"
#include "Agent.h"

AICohesion::AICohesion()
{

}

void AICohesion::Update()
{
	Neighbours n = m_agent->GetNeighbours();
	int numOfNeighbours = n.size();
	
	D3DXVECTOR3 centre;	
	for (int i = 0; i != numOfNeighbours; i++)
	{
		centre += n[i]->GetPosition();
	}
	centre *= (1.0f / (float)numOfNeighbours);

	// head towards centre
	D3DXVECTOR3 direction = centre - m_agent->GetPosition();
	m_agent->AddForce(direction);
}